package Vista;

import java.awt.*;
import javax.swing.*;

import Controlador.Sistema;
import Persistencia.AdministradorPersistenciaLoggin;
import Persistencia.PoolConnection;

import java.awt.event.*;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PanelLogueo extends JDialog {

	private static final long serialVersionUID = 1L;

	private static JTextField campoUsuario;
	private static JPasswordField campoClave;
	private JPanel campos;
	private JPanel botones;
	private JPanel internal;
	private JButton cancelar;
	private JButton aceptar;

	public PanelLogueo(JFrame ventana) {

		super(ventana,true);
		configurarPanel();
		configurarInternal();
		this.add(internal);
		this.setUndecorated(true);
		this.setLocation(540,260);
		this.pack();
		this.setSize(276, 89);
		this.setVisible(true);

	}

	private void configurarPanel() {

		campos = new JPanel ();
		botones = new JPanel ();
		campoUsuario = new JTextField(7);
		campoClave = new JPasswordField(8);
		aceptar = new JButton("Aceptar");
		cancelar = new JButton("Cancelar");
		campos.add(new JLabel("Usuario"));
		campos.add(campoUsuario);
		campoUsuario.addMouseMotionListener(new MouseMotionAdapter() {
			public void actionMotin(MouseEvent evt) 
			{
				System.out.println("campoUsuario.actionMotin, event="+evt);
				limpiarPantalla();
			}
		});
		campos.add(new JLabel("Clave"));
		campos.add(campoClave);
		botones.add(aceptar);
		
		aceptar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				System.out.println("aceptar.actionPerformed, event="+evt);				
				boolean a = true; //AdministradorPersistenciaLoggin.getInstancia().validaLoggin(campoUsuario.getText(), campoClave.getText());
				//SACAR ESTO PARA QUE ANDE EL LOGGIN
				a = true;
				//--------------------
				if (a)
				{
				 dispose();	
				}
				else
				{
					JOptionPane.showMessageDialog(null, "Error de usuario y Password", "Advertencia", JOptionPane.INFORMATION_MESSAGE);
				}
			}
		});
		
		botones.add(cancelar);
		cancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				System.out.println("cancelar.actionPerformed, event="+evt);
				System.exit(0);
			}
		});
		botones.add(new JButton("Registrar"));

	}

	private void configurarInternal() {
		internal = new JPanel ();
		internal.setLayout(new BorderLayout());
		internal.add(campos,BorderLayout.NORTH);
		internal.add(botones,BorderLayout.SOUTH);
	}

	public static void limpiarCampos() {
		campoUsuario.setText("");
		campoClave.setText("");
	}

	public static String getValorCampoUsuario() {
		return campoUsuario.getText();
	}

	public static String getValorCampoPassword() {
		return new String(campoClave.getPassword());
	}

	private void limpiarPantalla()
	{
		campoUsuario.setText("");
		campoClave.setText("");
		}

}
